package com.business;

import org.apache.http.HttpEntity;
import org.apache.http.impl.client.DefaultHttpClient;

import com.common.Constants;
import com.common.MyHttpClient;
import com.util.RegexUtil;
import com.util.UrlUtil;

public class QQHttpClient extends MyHttpClient{
	private String sid;
	private String farmAppURL;

	@Override
	protected void login() throws Exception{
		HttpEntity entity = UrlUtil.simulation4AccessURL(	httpClient,
															Constants.URL_LOGIN,
															UrlUtil.GET );
		String htmlDoc = UrlUtil.convertToString( entity );

		Constants.URL_LOGIN = RegexUtil.getMatchedObject(	htmlDoc,
															"action=\"(.*?)\"" );
		String preSid = RegexUtil.getMatchedObject( htmlDoc, "sid=(.*?)\"" );

		String login_url = "http://pt5.3g.qq.com/s?aid=nLoginqz&KqqWap_Act=3&sid="
				+ preSid;

		sid = UrlUtil.simulation4LoginQZ(	httpClient, Constants.URL_LOGIN,
											Constants.USERINFO_PARAS,
											Constants.USERINFO_VALUES,
											Constants.CHARSET, login_url );
		
		// switch to old web version
		System.out.println("switch to old web version begin----------------------");
		String oldUrl = "http://m.z.qq.com/iphone/index.jsp?g_f=13354&sid="
				+ sid;
		entity = UrlUtil.simulation4AccessURL( httpClient, oldUrl, UrlUtil.GET );
		entity.consumeContent();
		System.out.println("switch to old web version over----------------------");
		
		farmAppURL = "http://app20.z.qq.com/qzone_app/index.jsp?appid=353&sid="
				+ sid;
	}

	public String getSid(){
		return sid;
	}
	
	public String getFarmAppURL(){
		return farmAppURL;
	}
	
	public DefaultHttpClient getDefaultHttpClient(){
		return httpClient;
	}

}
